package com.kltn.zigo.data.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.kltn.zigo.R;
import com.kltn.zigo.data.loader.DistrictLoader;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DistrictAdapter extends BaseAdapter {

	private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    private DistrictLoader districtloader;
    
    public DistrictAdapter(Activity a, DistrictLoader dl) {
        activity = a;
        data=dl.GetDistrict();
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        districtloader = dl;        
    }
    
    public DistrictAdapter(Activity a, DistrictLoader dl, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        districtloader = dl;  
    }
	
	@Override
	public int getCount() {
        return data.size();
	}

	@Override
	public Object getItem(int position) {
        return position;
	}

	@Override
	public long getItemId(int position) {
        return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item_list_address, null);

        TextView district_id = (TextView)vi.findViewById(R.id.tvID);
        TextView district_name = (TextView)vi.findViewById(R.id.tvProvinceDistrict);
        
        HashMap<String, String> district = new HashMap<String, String>();
        district = data.get(position);
        // Setting all values in listview
        district_id.setText(district.get(districtloader.TAG_DISTRICT_ID));
        district_name.setText(district.get(districtloader.TAG_DISTRICT_NAME));
        return vi;
	}
}